package com.wicket.okrcomponent.base.service.impl;

import cn.hutool.core.bean.BeanUtil;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.wicket.okrcomponent.base.service.MOmsBizFrameContentTagRecordService;
import com.wicket.okrcomponent.base.service.dto.req.*;
import com.wicket.okrcomponent.common.dto.FieldInfo;
import com.wicket.okrcomponent.common.exception.BizException;
import com.wicket.okrcomponent.common.tools.StringUtils;
import com.wicket.okrcomponent.common.util.CommonFunctionHelper;
import com.wicket.okrcomponent.dal.mapper.mbg.OmsBizFrameContentTagRecordMapper;
import com.wicket.okrcomponent.dal.po.mbg.OmsBizFrameContentTagRecord;
import java.lang.reflect.Field;
import java.util.*;
import java.util.ArrayList;
import java.util.stream.Collectors;
//import com.wicket.okrcomponent.base.service.dto.res.*;

import org.apache.skywalking.apm.toolkit.trace.Tag;
import org.apache.skywalking.apm.toolkit.trace.Tags;
import org.apache.skywalking.apm.toolkit.trace.Trace;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

/**
 * @author ：
 * @since 2022/1/19 15:39
 *
 *
 * @version 1.0
 */
@Service
public class MOmsBizFrameContentTagRecordServiceImpl
  extends ServiceImpl<OmsBizFrameContentTagRecordMapper, OmsBizFrameContentTagRecord>
  implements MOmsBizFrameContentTagRecordService {

  @Autowired
  OmsBizFrameContentTagRecordMapper omsBizFrameContentTagRecordMapper;
/**
   * 2-10-11查消息标签记录[7307]
   * gen by moon at 7/19/2023, 7:49:34 PM
   */
 @Trace(operationName = "2-10-11查消息标签记录")
 @Tags({@Tag(key = "参数",value = "arg[0]"),
 @Tag(key = "返回值",value = "returnedObj")})
  @Override
  @Transactional(rollbackFor=Exception.class)
  public  OmsBizFrameContentTagRecord  queryMessageTagRcordDetail(QueryMessageTagRcordDetailReq reqDto) {
     
        try {
         reqDto.setIsValid("FALSE");
            QueryWrapper<OmsBizFrameContentTagRecord> queryWrapper = new QueryWrapper<>();
            Map<String, Object> fieldInfoMap = null;
            fieldInfoMap = CommonFunctionHelper.objectToMapForLamBda(reqDto);
            CommonFunctionHelper.buildQueryWrapperEq(queryWrapper, fieldInfoMap, new ArrayList<>());
            queryWrapper.orderByDesc("create_time");
            List<OmsBizFrameContentTagRecord> retList = super.list(queryWrapper);
            if(retList!=null && retList.size()>0){
                OmsBizFrameContentTagRecord retData = retList.get(0);
                
                return retData;
            }
            return null;
      } catch (Exception e) {
          e.printStackTrace();
          throw new BizException("-1",e,false);
      }
  }
/**
   * 2-10-11新增消息标签记录[7308]
   * gen by moon at 7/19/2023, 7:49:35 PM
   */
 @Trace(operationName = "2-10-11新增消息标签记录")
 @Tags({@Tag(key = "参数",value = "arg[0]"),
 @Tag(key = "返回值",value = "returnedObj")})
  @Override
  @Transactional(rollbackFor=Exception.class)
  public  String  addMessageTagRcord(OmsBizFrameContentTagRecord omsBizFrameContentTagRecord) {
     omsBizFrameContentTagRecord.setTagContentRecordId(CommonFunctionHelper.getUid());//DISTRIBUTED_ID
omsBizFrameContentTagRecord.setIsArchive("FALSE");
omsBizFrameContentTagRecord.setOperationInductionId(CommonFunctionHelper.getBaseInfoFromLocal().getSpecInductionRecordId());//CURRENT_INDUCTIONID
omsBizFrameContentTagRecord.setCreateInductionId(CommonFunctionHelper.getBaseInfoFromLocal().getSpecInductionRecordId());//CURRENT_INDUCTIONID
omsBizFrameContentTagRecord.setOperateTime(CommonFunctionHelper.getCurrentTime());//SYSTEM_CURRENT_TIME
omsBizFrameContentTagRecord.setCreateTime(CommonFunctionHelper.getCurrentTime());//SYSTEM_CURRENT_TIME
omsBizFrameContentTagRecord.setIsValid("FALSE");
omsBizFrameContentTagRecord.setSpaceId(CommonFunctionHelper.getBaseInfoFromLocal().getSpecSpaceId());//CURRENT_SPACEID
omsBizFrameContentTagRecord.setAppId(CommonFunctionHelper.getBaseInfoFromLocal().getSpecAppId());//CURRENT_APPID
     if(super.save(omsBizFrameContentTagRecord)){
        return omsBizFrameContentTagRecord.getTagContentRecordId();
     }else {
        return "-1";
     }
    
  }
}
